$(function(){
	// 登录页面js
	$(document).on('click','#login_submit', function () {
      	var buttons1 = [
	        {
	          	text: '请选择',
	          	label: true
	        },
	        {
	            text: '家长',
	            onClick: function() {
		            $.alert("以家长身份登录");
	            }
	        },
	        {
	            text: '学生',
	            onClick: function() {
	            	$.alert("以学生身份登录");
		            $.router.load("./stu_main.html");
	            }
	        },
	        {
	          	text: '教师',
	          	onClick: function() {
	            	$.alert("以教师身份登录");
	          	}
	        },
        ];
      	var buttons2 = [
	        {
	          	text: '取消',
	          	bg: 'danger'
	        }
      	];
        var groups = [buttons1, buttons2];
      	$.actions(groups);
  	});


	$(document).on("pageInit", "#stu_hw_page", function(e, pageId, $page){

			// 学生作业页面js
		var stu_hw_subject_selected = "green";
		var stu_hw_subject_unselected = "rgba(0, 0, 0, 0)"

		$("li.stu_hw_subject_option").click(function(event) {
			/* Act on the event */

			var origin = $(this).css('background-color');
			if (origin === stu_hw_subject_unselected) {
				$(this).css('background-color', stu_hw_subject_selected);
			}else if(origin === stu_hw_subject_selected){
				$(this).css('background-color', stu_hw_subject_unselected);
			}
		});

	});

	var toolbarTemplate = '<header class = "bar bar-nav">\
			<button class = "button button-link pull-right close-picker submit_selection">确定</button>\
			<h1 class = "title">请选择学年</h1></header>'

	$(document).on("pageInit", "#stu_grade_page", function(e, pageId, $page){

		var selection_submitted = false;

		$("#stu_grade_time_selection").picker({
			toolbarTemplate: toolbarTemplate,
			cols: [
				{
					textAlign: 'center',
					values: ['2015-2016年 第一学期', 
						'2015-2016年 第二学期', 
						'2015-2016年 第三学期', ],
				}
			],
			onOpen: function(){
				$(".submit_selection").click(function(event) {
					/* Act on the event */
					selection_submitted = true;
				});
			},
			onClose: function(picker, value, displayValue){
				if (selection_submitted) {
					console.log(picker.cols[0].activeIndex);
					console.log(picker.cols[0].displayValue);
					$("#content_block_title_stu_grade_year").html(picker.cols[0].displayValue);
					selection_submitted = false;
					// 发送请求获取 学生成绩学年学期信息
				};
			}
		});

	});

	$(document).on("pageInit", "#stu_evaluate_page", function(e, pageId, $page){
		var selection_submitted = false;
			
		$("#stu_grade_time_selection").picker({
			toolbarTemplate: toolbarTemplate,
			cols: [
				{
					textAlign: 'center',
					values: ['2015-2016年 第一学期', 
						'2015-2016年 第二学期', 
						'2015-2016年 第三学期', ],
				}
			],
			onOpen: function(){
				$(".submit_selection").click(function(event) {
					/* Act on the event */
					selection_submitted = true;
				});
			},
			onClose: function(picker, value, displayValue){
				console.log(picker.cols[0].activeIndex);
				console.log(picker.cols[0].displayValue);
				$("#content_block_title_stu_evaluate_year").html(picker.cols[0].displayValue);
				selection_submitted = false;
				// 发送请求获取 学生评语的学年学期信息
			}
		});
	});
	
	$(document).on('pageInit', '#stu_honor_page', function(event) {

		var honor_punish_map = new Map([
				["stu_honor_selected", 0],
				["stu_punish_selected", 1]
			]
			);

		$("#stu_honor_select_button a.tab-link").click(function(event) {
			/* Act on the event */
			if (!$(this).hasClass('active')) {
				$(this).addClass('active');
				$(this).siblings('a').eq(0).removeClass('active');
				var request_type = honor_punish_map.get($(this).attr('id'));
				console.log(request_type);
				// 根据request_type发送不同请求
			};
		});

		var selection_submitted = false;
			
		$("#stu_honor_time_selection").picker({
			toolbarTemplate: '<header class = "bar bar-nav">\
			<button class = "button button-link pull-right close-picker submit_selection" >确定</button>\
			<h1 class = "title">请选择学年</h1></header>',
			cols: [
				{
					textAlign: 'center',
					values: ['2015-2016年 第一学期', 
						'2015-2016年 第二学期', 
						'2015-2016年 第三学期', ],
				}
			],
			onOpen: function(){
				$(".submit_selection").click(function(event) {
					/* Act on the event */
					selection_submitted = true;
				});
			},
			onClose: function(picker, value, displayValue){
				console.log(picker.cols[0].activeIndex);
				console.log(picker.cols[0].displayValue);
				// 发送请求获取 学生奖罚的学年学期信息
			}
		});

	});

  	$.init();

});